package com.ynjtc.desserts.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ynjtc.desserts.entity.Dessert;
import com.ynjtc.desserts.mapper.DessertMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * @Author: lihua
 * @Date: 2025/9/25 09:15
 * @Version: v1.0.0
 * @Description:
 **/
@Service
@Slf4j
public class DessertService {

    @Autowired
    private DessertMapper dessertMapper;

    public Dessert addDessert(Dessert dessert){
        QueryWrapper<Dessert> wrapper = new QueryWrapper<>();
        wrapper.eq("dessert_name",dessert.getDessertName());
        if( dessertMapper.exists(wrapper)){
            log.error("分类已存在 name ==> {} ", dessert.getDessertName());
            return null;
        }else {
            dessert.setId(null);
            dessert.setCreateTime(LocalDateTime.now());
            dessert.setStatus(1);
            dessertMapper.insert(dessert);
            return dessert;
        }
    }

}
